$(document).on('ready', function(e)
{
  /*
   * Botón para borrar a un usuario
   */
  $('a[data-delete]').on('click', function(e)
  {
    e.preventDefault();
    var director_id = $(this).data('delete');
    var $RowDirector = $('#row_director_' + director_id);

    $.ajax('orquesta/directores/actions.php?action=delete', {
      data: {'director_id': director_id},
      dataType: 'json',
      type: 'post',
      beforeSend: function(jqXHR, Settings)
      {
        $RowDirector.addClass('deleting');
      },
      complete: function(jqXHR, status_text)
      {
        if($RowDirector){
          $RowDirector.removeClass('deleting');
        }
      },
      error: function(jqXHR, status_text, error_thrown)
      {
        alert('Ocurrión un error al procesar la solicitud. ('
          + error_thrown + ')');
      },
      success: function(Response, status_text, jqXHR)
      {
        if(Response.error){
          alert(Response.message);
        } else {
          $RowDirector.fadeOut('fast', function(e)
          {
            $RowDirector.remove();
          });
        }
      }
    });
  });
});